package views
{
	import views.IView;
	import views.interfaces.ILoading;
	import main.ViewMng;
	
	public class LoadingView implements IView
	{
		protected var _loading:ILoading;
		
		
		public function LoadingView()
		{
		}
		
		public function show():void
		{	
			if( _loading == null )
			{
				_loading = ViewMng.instance().getUIByName( UIAsset.UI_LOADING ) as ILoading;
				
				if( _loading == null )
				{
					return;
				}
			}
			
			ViewMng.instance().addPopup( _loading );
			
			_loading.show();
			
		}
		
		public function close():void
		{
			if( _loading )
				_loading.close();
		}
		
		public function getUIName():String
		{
			return UIAsset.UI_LOADING;
		}
		
		public function isInited():Boolean
		{
			return _loading != null;
		}
		
		public function isShowed():Boolean
		{
			return _loading && _loading.isShowed();
		}
		
		public function setProgress( desc:String, loadedBytes:int, 
									 totalLoadedBytes:int,  speed:Number, percent:Number ):void
		{
			if( !_loading ) return;
			
			if(  !isShowed() )
			{
				ViewMng.instance().showLoading();	
			}	
			
			_loading.setProgress( desc, loadedBytes, totalLoadedBytes, speed, percent );
			
		}
		
		
	}
}